<?php
	
	session_start();
	require("connect.php");
	$link = connect_APO();
		
	$type= $_SESSION['type'];
	
	if (!session_is_registered('ID')) :
		header('Location: login.php');
	endif;
	
	if ($type != 'coordinator'){
		header('Location: index.php');
	}
	
	require("header+logoutB.php");
	headerL();
		
	$searchid=$_POST['searchid'];
	if(strcmp($searchid,"")==0){
		$searchid = "%";
	} else {
		$searchid= "%".$searchid."%";
	}
	$searchfname=$_POST['searchfname'];
	if(strcmp($searchfname,"")==0){
		$searchfname = "%";
	} else {
		$searchfname= "%".$searchfname."%";
	}
	$searchlname=$_POST['searchlname'];
	if(strcmp($searchlname,"")==0){
		$searchlname = "%";
	} else {
		$searchlname= "%".$searchlname."%";
	}
	$searchnumber=$_POST['searchnumber'];
	if(strcmp($searchnumber,"")==0){
		$searchnumber = "%";
	} else {
		$searchnumber= "%".$searchnumber."%";
	}
	$searchtotcredit=$_POST['searchtotcredit'];
	if(strcmp($searchtotcredit,"")==0){
		$searchevalTC = "!= '-1'";
	} else {
		$searchevalTC = ">=";
	}
	$searchmidweekleader=$_POST['searchmidweekleader'];
	if(strcmp($searchmidweekleader,"")==0){
		$searchevalML = "!=";
		$searchmidweekleader="2";
	} else if(strcmp($searchmidweekleader,"no")==0){
		$searchevalML = "=";
		$searchmidweekleader="0";

	} else {
		$searchevalML = "=";
		$searchmidweekleader="1";
	}
	$searchbrother=$_POST['searchbrother'];
	$searchpledges=$_POST['searchpledges'];
	if(strcmp($searchbrother,"no")==0){
		$searchstatus = "%";
	} else if(strcmp($searchbrother,"yes")==0){
		$searchstatus= "Brother";
	} else if(strcmp($searchpledges,"yes")==0){
		$searchstatus= "Pledge";
	}
	
	$sql="SELECT * FROM `users` WHERE `ID` LIKE '".$searchid."'
AND `Fname` LIKE '".$searchfname."'
AND `Lname` LIKE '".$searchlname."'
AND `PhoneNumber` LIKE '".$searchnumber."'
AND `TotCredit` ".$searchevalTC.$searchtotcredit."
AND `ML` ".$searchevalML.$searchmidweekleader."
AND `Status` LIKE '".$searchstatus."';";

	$result=mysql_query($sql);
	
	echo "<html>
<body class='main'>

<FONT class='mainFont'>
  <CENTER>
    <!--<p><img src = 'images/apopic.jpg'></p>-->
    <br>
	<br>
	  <div class='headerTable'>
	  <b class='b1f'></b><b class='b2f'></b><b class='b3f'></b><b class='b4f'></b>
	  <div class='contentf'>
		  <div class = 'headerText'>
				View User Information:
		  </div>
		  <div class='viewRow'><div class='floater' id='vID'>ID</div><div class='floater' id='vName'>Name</div><div class='floater' id='vPhone'>Phone Number</div>
		       <div class='floater' id='vMC'>Midweek Credits</div><div class='floater' id='vML'>Midweek Leader?</div>
			   <div class='floater' id='vStat'>Status</div>
		  </div>
		  ";
		  
		  while($row = mysql_fetch_array($result) ){
			$id = $row['ID'];
			$fname = $row['Fname'];
			$lname = $row['Lname'];
			$phone = $row['PhoneNumber'];
			$totcred = $row['TotCredit'];
			$ml = $row['ML'];
			if($ml == 0){
				$ml = "No";
			} else {
				$ml = "Yes";
			}
			$status = $row['Status'];
			
			echo "<div class='viewRow'><div class='floater' id='vID'>$id</div><div class='floater' id='vName'>$fname $lname</div><div class='floater' id='vPhone'>$phone</div>
					   <div class='floater' id='vMC'>$totcred</div><div class='floater' id='vML'>$ml</div><div class='floater' id='vStat'>$status</div>
				  </div>";
		  }		 
				  
				  echo "</div>
	  <b class='b4f'></b><b class='b3f'></b><b class='b2f'></b><b class='b1f'></b>
		</div>
	</center>
</font>
</body>
</head>
</html>";

	require("footer.php");
	footer();
mysql_close($link);
?>